package com.yanqu.road.server.cmd.activity.common;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.logic.rank.RankListModel;
import com.yanqu.road.pb.commonactivity.CommonActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.CommonActivityMgr;
import com.yanqu.road.server.manger.activity.CommonActivityRankMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;

@Cmd(code = Protocol.S_COMMON_ACTIVITY_RANK, desc = "个人活动积分排行榜")
public class CommonActivityRankListCmd extends AbstractCommand {

    private int activityId;
    private int rankType;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CommonActivityProto.CommonActivityRankListReqMsg reqMsg = CommonActivityProto.CommonActivityRankListReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        rankType = reqMsg.getRankType();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

    }

    @Override
    public void sendData(GamePlayer player) {
        CommonActivityProto.CommonActivityRankListRespMsg.Builder respMsg = CommonActivityProto.CommonActivityRankListRespMsg.newBuilder();
        respMsg.setMyRank(-1);
        ActivityInfo openActivityInfo = CommonActivityMgr.getOpenCommonActivityInfo(activityId);
        if (null != openActivityInfo) {
            if(1 == rankType){//跨服万能活动
              /*  RankProto.RankListMsg.Builder rankListMsg = CrossDataMgr.getCrossRankActivityRankMsg(activityId);
                respMsg.setRankList(rankListMsg);
                respMsg.setMyRank(ActivityMgr.getMyCrossRank(player.getUserId(), rankListMsg));*/
                CommonActivityProto.CommonActivityRankListReqMsg.Builder msg = CommonActivityProto.CommonActivityRankListReqMsg.newBuilder();
                msg.setActivityId(activityId);
                msg.setRankType(rankType);
                player.sendPacket(Protocol.C2_CROSS_GET_COMMON_ACTIVITY_RANK, msg);
              return;
            }else {
                RankListModel rankListModel = CommonActivityRankMgr.getRankListModel(openActivityInfo.getActivityId());
                if (null != rankListModel) {
                    respMsg.setRankList(rankListModel.getRankListMsg());
                    respMsg.setMyRank(rankListModel.unlockGetMyRank(player.getUserId()));
                }
            }
        }
        player.sendPacket(Protocol.U_COMMON_ACTIVITY_RANK, respMsg);
    }
}
